// Desc: 公共方法
import * as XLSX from "xlsx";

export function getStatus(item) {
    if (item.order_status === 0 || item.order_status === 3) {
        if (item.status === 1) {
            return '待支付'
        } else if (item.status === 2) {
            if (item.address_id) {
                return '待确认'
            } else {
                return '待自提'
            }
        } else if (item.status === 3) {
            return '运输中'
        } else if (item.status === 4) {
            return '待收货'
        } else if (item.status === 5) {
            return '已完成'
        }
    }  else if (item.order_status === 1) {
        return '退款中'
    } else if (item.order_status === 2) {
        return '退款成功'
    }
}
export const defaultMockMenu = [
    {
        code: 'home',
        name: '首页'
    },
    {
        code: 'postManager',
        name: '婚庆论坛',
        children: [
            {
                name: '帖子列表',
                code: 'post',
            },
            {
                name: '帖子管理',
                code: 'postAdmin',
            },
        ]
    },

    {
        code: 'userCenter',
        name: '个人中心',
        children: [
            {
                code: 'my',
                name: '个人中心',
            },
            {
                code: 'collect',
                name: '我的收藏'
            },
            {
                code: 'like',
                name: '我的点赞'
            },
        ]
    },
    {
        code: 'banner',
        name: 'Banner管理',
    },
    {
        code: 'notice',
        name: '公告管理',
    },
    {
        code: 'news',
        name: '新闻管理',
    },
    {
        name: '婚庆套餐管理',
        code: 'Product',
        children: [
            {
                name: '套餐分类',
                code: 'ProductCategory',
            },
            {
                name: '套餐列表',
                code: 'ProductList',
            },
        ]
    },
    {
        name: '婚庆套餐列表',
        code: 'ProductList2',
    },
    {
        code: 'ProductOrder',
        name: '订单管理',
    },
    {
        code: 'myOrder',
        name: '我的订单',
    },
    {
        name: '用户管理',
        code: 'user-management',
        icon: 'img_3',
        activeIcon: 'img_3_active',
        children: [
            {
                name: '角色管理',
                code: 'role',
            },
            {
                name: '用户管理',
                code: 'user',
            }
        ]
    },
]

export const exportToExcel = (name,data = []) => {
    if (!name) {
        name = '导出文件'
    }
    if (!data) return
    // 创建一个工作簿
    const workbook = XLSX.utils.book_new();
    // 创建一个工作表
    const worksheet = XLSX.utils.aoa_to_sheet([
        ...data
    ]);

    // 将工作表添加到工作簿
    XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');

    // 生成Excel文件
    XLSX.writeFile(workbook, name + '.xlsx');
};
